<img src='' id='GoodsConEdit_Banner' onerror='this.src="../Public/Image/base.png"'  style='width:100%' alt='暂无图片' /> <!--广告位-->
<div style='margin:10px auto;display:flex'>
	<div style='width:100px;text-align:right'>分类选择：</div>
	<div id='GoodsConEdit_TypeSelArea1'>
		<span id='GoodsConEdit_TypeSelArea1_Sub1'></span>　
		<button id='GoodsConEdit_TypeSelArea1_Sub2'>切换</button>
	</div>
	<div style='flex:1;display:none' id='GoodsConEdit_TypeSelArea2'>
		<select id="GoodsConEdit_TypeSel1"></select>
		<select id="GoodsConEdit_TypeSel2"></select>
		<select id="GoodsConEdit_TypeSel3"></select>
	</div>
</div>

<div style='margin:10px auto;display:flex'>
	<div style='width:100px;text-align:right'>商品名称：</div>
	<div style='flex:1'><input type="text" id='GoodsConEdit_Title' style='width:90%' /></div>
</div>
<div style='margin:10px auto;display:flex'>
	<div style='width:100px;;text-align:right'>商品编号：</div>
	<div style='flex:1'><input type="text" id='GoodsConEdit_Number' />(可选)</div>
</div>
<div style='margin:10px auto;display:flex'>
	<div style='width:100px;text-align:right'>商品价格：</div>
	<div style='flex:1'><input type="text" id='GoodsConEdit_Price' /></div>
</div>

<div style='margin:10px auto;display:flex'>
	<div style='width:100px;;text-align:right'>商品详情：</div>
	<div style='flex:1'><textarea id='GoodsConEdit_Info' style='width:90%;height:150px;resize:none' ></textarea></div>
</div>

<div style='margin:10px auto;display:flex'>
	<div style='width:100px;text-align:right'>图片展示：</div>
	<div style='flex:1'>
		<div id='GoodsConEdit_ImgList'></div>
		<div style='position:relative;margin:10px' id='GoodsConEdit_Img_Area'>
			<img src="../Public/Image/file.png" alt="" style='width:40px'>
			<input type="file" id='GoodsConEdit_Img' style='width:40px;height:40px;opacity:0;position:absolute;top:0px;left:0px;' />
		</div>
	</div>
</div>

<div style='margin:20px auto;display:flex;position:relative'>
	<div style='width:100px;text-align:right'>验证码　：</div>
	<div style='flex:1'>
		<input id='GoodsConEdit_Code' style='width:100px' />
		<img src="interface.php?type=code" style='position:absolute;left:230px;bottom:0px;width:150px' onclick='ChangeCode(this)' id='GoodsConEdit_CodeImg' alt="点击">
	</div>
</div>

<div style='text-align:center;margin:20px auto'>
	<button id='GoodsConEdit_SubBtn'>提交</button>
	<button id='GoodsConEdit_BackBtn'>返回</button>
</div>



<script>
	var edit_id = sessionStorage.goods_edit_id;
	var GoodsConEdit_info = '';


	StoreGoodsEdit_GetImgList();

	//加载图片列表
	function StoreGoodsEdit_GetImgList(){
		if($('#GoodsConEdit_ImgList').html().length > 0){
			GoodsConEditImgs_View();
		}else{
			Ajax({},function(res){
				$('#GoodsConEdit_ImgList').html(res);
			},'Template/GoodsConEditImgs.html?a='+Math.random());
		}
	}






	//选择并上传图片
	var GoodsConEdit_Img = document.getElementById('GoodsConEdit_Img');
	GoodsConEdit_Img.onchange=function(){
		Notice('图片上传中......');
		var file = GoodsConEdit_Img.files[0];
		if(CheckFile(file,200*1024) != true){
			Notice('');
			A('js-图片只支持jpg,gif,png格式，且不得大于300k!');return;
		}
		//sessionStorage.removeItem('img_list_'+edit_current_id);	//删除当前id商品对应的图片列表缓存


		var formData = new FormData();
		formData.append('type','GoodsImageAdd');
		formData.append('img',file); //添加文件
		formData.append('goods_id',edit_id); //添加信息
		formData.append('store_id',StoreInfo.id); //添加信息
		Ajax_FormData2(formData,after_url,function(res){
			//C(res);
			switch(res){
				case 'err1':A('图片数量超限！');break;
				case 'err2':A('文件上传失败！');break;
				case 'err4':
				case 'err5':
					A('操作失败！');
					break;
				case 'ok':
					A('上传成功！');
					StoreGoodsEdit_GetImgList();
				break;
			}
			Notice('');
		});

	}





	$('#GoodsConEdit_TypeSelArea1_Sub2').click(function(){
		//加载三级商品分类 
		$('#GoodsConEdit_TypeSelArea2').show();
		$('#GoodsConEdit_TypeSelArea1').hide();
		// $.getScript('http://www.tools.top/goods_type.js',function(){
		// 	GoodsTypeInit('#GoodsConEdit_TypeSel1','#GoodsConEdit_TypeSel2','#GoodsConEdit_TypeSel3');
		// });
		GetGoodsType(function(GoodsType){
			C(GoodsType);
			GoodsTypeInit(GoodsType,GoodsConEdit_TypeSel1,GoodsConEdit_TypeSel2,GoodsConEdit_TypeSel3);
		});
	});


	$('#GoodsConEdit_SubBtn').click(function(){
		if($('#GoodsConEdit_TypeSelArea2').is(':visible')){
			var t1 = $('#GoodsConEdit_TypeSel1').find('option:selected').val();
			var t2 = $('#GoodsConEdit_TypeSel2').find('option:selected').val();
			var t3 = $('#GoodsConEdit_TypeSel3').find('option:selected').val();
			var t1_text = $('#GoodsConEdit_TypeSel1').find('option:selected').text();
			var t2_text = $('#GoodsConEdit_TypeSel2').find('option:selected').text();
			var t3_text = $('#GoodsConEdit_TypeSel3').find('option:selected').text();
			var type_set = t1_text+"--"+t2_text+"--"+t3_text;
			//C(type_set);
		}else{
			var t1 = GoodsConEdit_info.tid1;
			var t2 = GoodsConEdit_info.tid2;
			var t3 = GoodsConEdit_info.tid3;
			var type_set = GoodsConEdit_info.type_set;
		}
		var GoodsTitle = ChangeChar($('#GoodsConEdit_Title').val().trim());
		Field_Check(/^.{1,50}$/,GoodsTitle,'js商品名1-50个字符!');

		var GoodsNumber = $('#GoodsConEdit_Number').val().trim();
		Field_Check(/^[0-9]{1,4}$|^$/,GoodsNumber,'js编号为0-4四位数字!');

		var GoodsPrice = $('#GoodsConEdit_Price').val().trim();
		Field_Check(/^[1-9][0-9]{0,8}(\.[0-9]{1,2})?$/,GoodsPrice,'js价格输入有误!');

		var GoodsInfo = ChangeChar($('#GoodsConEdit_Info').val().trim());
		Field_Check(/^.{1,}$/,GoodsInfo,'js商品详情不得为空!');

		var code = ChangeChar($('#GoodsConEdit_Code').val().trim());
		Field_Check(/^.{1,}$/,code,'js验证码不得为空!');

		var data = {
			type:'StoreGoodsEdit',
			id:edit_id,
			title:GoodsTitle,
			number:GoodsNumber,
			price:GoodsPrice,
			info:GoodsInfo,
			code:code,
			t1:t1,
			t2:t2,
			t3:t3,
			type_set:type_set,
			banner:GoodsConEdit_info.banner
		}
		Ajax2(data,function(res){
			ChangeCode(document.getElementById('GoodsConEdit_CodeImg'));	//切换验证码
			if(res == 'ok'){
				A('操作成功!');
			}else if(res == 'err2'){
				A('验证码不正确！');
				return;
			}
			GCE_BackCon();
			GoodsCon_Init();
			//$('#StoreGoodsAdd_Code2').trigger('click');
		},after_url);
	});

	GCE_GetGoodsInfo();

	function GCE_GetGoodsInfo(){
		var data = {
			type:'GetGoodsInfo',
			id:edit_id
		};
		Ajax2(data,function(res){
			GCE_GetGoodsInfo_Parse(res);
		},after_url);
	}

	function GCE_GetGoodsInfo_Parse(res){
		if(/^{"id":.*}$/.test(res)){
			GoodsConEdit_info = JSON.parse(res);
			//C(GoodsConEdit_info);
			if(GoodsConEdit_info.banner){
				var GoodsConEdit_Banner = upyun_shop_img+GoodsConEdit_info.banner;
			}else{
				var GoodsConEdit_Banner = base_img;
			}
			$('#GoodsConEdit_Banner').attr('src',GoodsConEdit_Banner);
			$('#GoodsConEdit_Title').val(ChangeChar(GoodsConEdit_info.title,1));
			$('#GoodsConEdit_Number').val(GoodsConEdit_info.number);
			$('#GoodsConEdit_Price').val(GoodsConEdit_info.price);
			$('#GoodsConEdit_Info').val(ChangeChar(GoodsConEdit_info.info,1));
			$('#GoodsConEdit_TypeSelArea1_Sub1').text(GoodsConEdit_info.type_set);
			$('#GoodsConEdit_TypeSel1').val(GoodsConEdit_info.tid1);
		}
	}


	$('#GoodsConEdit_BackBtn').click(function(){
		GCE_BackCon();
	});

	function GCE_BackCon(){
		$('input').val('');
		$('textarea').val('');
		$('#GoodsCon_List').show();
		$('#GoodsCon_AddBtn').show();
		$('#GoodsCon_Edit').hide();
	}

</script>